I have a website:
www.mydomain.com/subfolder/subfolder/index.php
How could always hide the directory names from the url. I mean always hide the 2 subfolders' names from the url as the page changes.
Example:
These urls:
www.mydomain.com/subfolder/subfolder/index.php
www.mydomain.com/subfolder/subfolder/about.php
www.mydomain.com/subfolder/subfolder/contact.php
...
Becomes:
www.mydomain.com/index
www.mydomain.com/about
www.mydomain.com/contact
...
I want to use the last mentioned urls for requesting these pages, too, without typing a horrible long url.
you can find some good hints when you will look for mod_rewrite or mod rewrite in htaccess.
If you have access to the Rewrite engine, you can use a simple rewriting pattern similar to this:
RewriteRule ^/(.*)$ /subfolder/subfolder/$1.php
Related
I'm just new to .htacces
I want:
example.com/page.php?page=how-to-learn
changed to:
example.com/how-to-learn
I google'd some and tried but no change url.
That's not how .htaccess work : it won't change your links to display the corrected version, but it looks for a match in the expressions you'll write into it to rewrite the correct parameters.
For example, in your code, your .htaccess sould look something like this :
RewriteEngine On
RewriteRule ^([a-z-]+)$ page.php?page=$1 [QSA,L]
If you write example.com/how-to-learn in your browser, you'll be able to see the content of example.com/page.php?page=how-to-learn.
I advise you to be VERY careful though : as the expression is VERY permissive, you'll have to check in the page.php file that the file if legitimately allowed to be loaded.
I want to get a URL scheme exact like SO's question URL.
Like http://stackoverflow.com/questions/6035363/so-like-url-with-mod-rewrite
this page can be accessed with http://stackoverflow.com/questions/6035363
but then it redirects to the http://stackoverflow.com/questions/6035363/so-like-url-with-mod-rewrite
I need to do the same.
My page will be in the root directory named article.php
the url will be like
article.php?id=1&title=some_text
i want it to be accessed with [any of these will do]
acticle.php/id/1/some_text
or
acticle/id/1/some_text
or
acticle/id/1&title=some_text
[Sorry i really dont know about mod_rewrite so i read some question and googled some cheat sheets but none of them worked :(
So looking for some copy-paste solution]
It's best if you divide and conquer the URL to reverse engineer it.
So a few key points:
6035363 is the important part of the URL as it's the question ID.
Everything else is arbitrary SEO, friendly URLs
Having multiple URLs of the same page will hurt SEO, so stick to one URL format
With that said, article/id/some_keyword_text is the format I suggest. The following RewriteRules will handle it.
RewriteEngine On
RewriteBase /
RewriteRule ^article/(\d+)/?$ test/article.php?id=$1 [L]
RewriteRule ^article/(\d+)/([\w-]+)/?$ test/article.php?id=$1&title=$2 [L]
The first rule redirects article/id with an optional trailing slash. The second rule redirects article/id/some_keyword_text with an optional trailing slash. some_keyword_text may only contain alphanumeric, underscore, or dash characters.
Note: The redirection for URLs of format article/id happens at the page level. So this is not a RewriteRule, but logic in the page that redirects when title is not set. I'm guessing a 301 Redirect to ensure point #3.
Can I create a clean URL for WebBroker webpages/applications ?
A typical WebBroker URL normally looks like:
hxxp://www.mywebsite.com/myapp.dll?name=fred
or
hxxp://www.mywebsite.com/myapp.dll/names/fred
What I would prefer is:
hxxp://www.mywebsite.com/names/fred
Any idea how I can achieve this with Delphi/WebBroker ? (ISAPI/Apache)
The typical way of doing this is to use apache's mod_rewrite to redirect requests to the url w/ parameters. Many, many applications do this to create 'human readable' and more search engine friendly urls.
For example, you might add this rule to make action=sales&year=2009 look like sales-2009.htm:
RewriteRule ^sales-2009.htm?$ index.php?action=sales&y=2009 [L]
When the user goes to 'sales-2009.htm', its actually redirected to the php page with the appropriate parameters. To the end user, though, it still displays sales-2009.htm in the browser's url bar.
You can, of course, use regular expressions w/ mod_rewrite, such that you can make the redirections much more flexible. You could, for example, make a single expression in the above example that would map any year to the correct parameter.
Thanks to the people that've helped me so far with this, I'm ready for the last step, I think.
I've got my URLs looking like this.
/brochure.php?cat_path=35&name=concrete-intermediate-posts
This is great and finally I just need to know how to turn that URL into this desired URL:
/brochure/35/concrete-intermediate-posts
Just like the Stack Overflow format.
Could anyone help me with the correct .htaccess rule?
Also, if I have other get variables in other sections, will this re-write harm them? (they use different variable names)
Thanks
With mod_rewrite you will rather do the opposite: rewrite a URL path like /brochure/35/concrete-intermediate-posts internally to /brochure.php?cat_path=35&name=concrete-intermediate-posts:
RewriteRule ^([^/]+)/(\d+)/([^/]+)$ $1.php?cat_path=$2&name=$3 [L,QSA]
The other side, using a URL path like /brochure/35/concrete-intermediate-posts instead of /brochure.php?cat_path=35&name=concrete-intermediate-posts in the HTML documents, would be done with PHP.
I Hope you mean something like this:
RewriteEngine On
RewriteBase /
RewriteRule ^brochure/([0-9]+)/([-a-zA-Z0-9]+)$ /brochure.php?cat_path=$1&name=$2 [L]
I need to grab some of my website's old URLs and do a 301 redirect to the new ones, since they are already indexed and we don't want to loose relevance after the change. The old URL is in fact very ugly and for some reason everything I try to do to rewrite it does not work. Here it is:
http://www.mywebsite.com/ExibeCurso.asp?Comando=TreinamentoGeral&codCurso=136&Titulo=Como%20Estruturar%20um%20Sistema%20Gerencial%20de%20Controles%20Organizacionais,13
Basically, I need to translate it into something like:
http://www.mywebsite.com/curso/136
From the old URL I need to check if the user typed "ExibeCurso.asp"; then I know I must send him here: /curso. I must also grab the integer that was in the querystring parameter "codCurso" (136). What is the regular expression I must use for this. I am using ISAPI_Rewrite 3, which basically implements htaccess on IIS, so there should be no difference in terms of syntax. Thanks.
Try this rule:
RewriteCond %{QUERY_STRING} ^([^&]*&)*codCurso=([0-9]+)(&.*)?$
RewriteRule ^/ExibeCurso\.asp$ /curso/%2? [L,R=301]
But I’m not sure whether ISAPI Rewrite requires the pattern to begin with a slash.
Off the top of my head, something like this should work:
RewriteRule ^ExibeCurso.asp(.*)$ http://www.mywebsite.com/curso/$1 [L,R=301]
That would at least send the traffic to /curso/ with all parameters attached. Maybe it's best to process it from there.