How would I go about making my site use organic urls (like http://www.mysite.com/aboutus) - i don't want to use a CMS - my site is powered from index.php is there anyway of getting the text after the / so that I can select that page from the database? I'd rather not do /?aboutus
Thank you :D
You have to use a URL Rewrite engine.
Apache HTTP Server provides URL rewriting through the mod_rewrite module. You may want to check out these articles to get started:
Added Bytes: URL Rewriting for Beginners
Apache: URL Rewriting Guide
You can use mod_rewrite as others suggested. For example the following will map http://my.site.com/page to http://my.site.com/index.php?module=page
RewriteEngine on
RewriteRule ^/([a-z0-9]+)/?$ /index.php?module=$1 [L,QSA]
If you would like to use RESTful URLs throughout your site, here is a handy reference from microformats.org: rest/urls
Related
I did a search of previous questions about URL redirects with parameters, but none seem to speak to my particular problem. I'm not a programmer so I don't really know how to adapt other suggestions to my situation. Specific HTACCESS strings to try (and adapt for other URLs) would really help me.
I did an SEO restructure of my WP blog permalinks and I am finding that although the naked URLs are redirecting OK, URLs with parameters are not redirecting, they are going to a 404 error. I need URL parameters because my site is multilingual (Transposh plugin) so the "lang" parameter tells the site what language to translate the content to.
I think I may need to create a bunch of HTACCESS redirects that will redirect old URLs with a language parameter to the new permalinks for those URLs and pass the lang parameter through.
An example of this would be:
Source URL: /this-old-postname/?lang=(*)
Destination URL /blog/this-new-postname/?lang=$
There's no way to predict the URL pattern (although the parameter pattern is predictable) as each URL was tweaked for best SEO contribution.
I expect I'll need to write lots of these, each unique, so if you are able to provide an example can you please provide it for two redirects which would work for the following actual examples?
Source: http://www.travelnasia.com/thailand/bangkok/don-mueang-airport/?lang=zh
Destination: http://www.travelnasia.com/thailand/don-mueang-airport-bangkok/?lang=zh
Source: http://www.travelnasia.com/blog/map-attractions-bangkok-skytrain/?lang=zh
Destination: http://www.travelnasia.com/blog/bangkok-skytrain-bts-mrt-lines/?lang=zh
MOD_REWRITE is already enabled and standard redirects created in HTACCESS do work. I am pretty sure to achieve this I will need to use:
RewriteCond %{QUERY_STRING} ^lang=(.*)$
I understand this ensures the query string is read from the source URL.
I thought a redirect rule like this should work, but it doesn't:
RewriteRule ^test-redirect/$ http://test.travelnasia.com/destination/hanoi/hanoi-vietnam-destination-guide/$1 [L,QSA]
I've tried lots of other combinations but none of them seem to work.
Thanks in advance for any help offered.
Tony
If you don't mind including other query string parameters, [QSA] (query string append) is by far your simplest option.
Make it a 301 redirect with [R=301] if this is permanent change.
This should work for your purposes
RewriteEngine on # if not already enabled
RewriteRule ^thailand/bangkok/don-mueang-airport/?$ /thailand/don-mueang-airport-bangkok/ [QSA,R=301]
RewriteRule ^/blog/map-attractions-bangkok-skytrain/?$ /blog/bangkok-skytrain-bts-mrt-lines/ [QSA,R=301]
# ...
May be a noob question but I'm just starting playing around with apache and have not found a precise answer yet.
I am setting up a web app using url-rewriting massively, to show nice urls like [mywebsite.com/product/x] instead of [mywebsite.com/app/controllers/product.php?id=x].
However, I can still access the required page by typing the url [mywebsite.com/app/controllers/product.php?id=x]. I'd like to make it not possible, ie. redirect people to an error page if they do so, and allow them to access this page with the "rewritten" syntax only.
What would be the easiest way to do that? And do you think it is a necessary measure to secure an app?
In your PHP file, examine the $_SERVER['REQUEST_URI'] and ensure it is being accessed the way you want it to be.
There is no reason why this should be a security issue.
RewriteCond %{REDIRECT_URL} ! ^/app/controllers/product.php$
RewriteRule ^app/controllers/product.php$ /product/x [R,L]
RewriteRule ^product/(.*)$ /app/controllers/product.php?id=$1 [L]
The first rule will redirect any request to /app/controllers/product.php with no REDIRECT_URL variable set to the clean url. The Rewrite (last rule) will set this variable when calling the real page and won't be redirected.
I have a bit of a complex question. I am moving sites from
http://www.hikingsanfrancisco.com
to
http://www.comehike.com
The directory structures will not be the same throughout both sites. What are some of the best practice things I can do in order to retain most of my existing SEO strength in both the general domain and individual pages for searches related to the other pages?
Thank you,
Alex
If most of the URLs are staying the same and just the domain is changing, you could create an .htaccess file in the root folder at the old site with the following:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.comehike.com/$1 [R=301,L]
This will make hikingsanfrancisco.com/some-page go to comehike.com/some-page.
Otherwise in that same htaccess file you could add a line for each redirect. So if hikingsanfrancisco.com/big-hikes is now going to comehike.com/even-bigger-hikes the redirect would look like:
Redirect 301 /big-hikes http://www.comehike.com/even-bigger-hikes
That 301 tells Google to now consider the new URL correct.
To redirect the whole site no matter what to the new URL you could use this:
Redirect 301 / http://www.comehike.com/
A 301 Redirect, page by page, is the best option (If you can use regular expressions is easier). Redirect the old page to a page in the new site with similar content.
Use the change of address tool in Google Webmasters tools.
Try to contact some of yours referrals to change the links that target your site.
Hey all, I'm having all kinds of problems with a bunch of apache redirects just now and could really use some help!
I'm wating to put in a 301 redirect for a load of urls from a client's old site to their new site in the following format;
Old - page.php?pageNum_rs_all=0&totalRows_rs_all=112
New - page/sub?foo=bar
The values in the query sting for the old site don't in any way tie up to any ids or references on the new site, I only want to match that specific request and redirect to the new page.
It feels like I've tried just about every combination of rewriterule I can find online but still nothing seems to be working. This is running on Apache 2.2.
The rule I started with (and keep going back to) is;
RewriteRule ^/page.php\?pageNum_rs_all=0&totalRows_rs_all=112 /page/sub?foo=bar [R=301,L,NE]
Any help would be greatly appreciated!
c.
The reason that this doesn't work is that RewriteRule can't see the QueryString. To get at the Query String, you need to use RewriteCond. See http://wiki.apache.org/httpd/RewriteQueryString for examples of how this works.
I've always tended to use use a series of 301 redirects in the following manner
Redirect 301 /oldpage /newpage
I'm managing an instance of Wordpress where the URLs are in the following format:
http://www.example.com/example-category/blog-post-permalink/
The blog author did an inconsistent job of adding categories to posts, so while some of them had legitimate categories in their URLS, at least half are "uncategorised".
I can easily change Wordpress to render the URL without the category name (e.g., http://www.example.com/blog-post-permalink/), but I'd like to create a mod_rewrite rule to automatically redirect any requests for the previous format to the new, cleaner one.
How can I use a mod_rewrite recipe to handle this, taking into account that I want to honor requests for the real WordPress directories that are in my webroot?
Something as simple as:
RewriteRule ^/[^/]+/([^/]+)/?$ /$2 [R]
Perhaps would do it?
That simple redirects /foo/bar/ to /bar.