I need some help with mod_rewrite rule in apache.
This module is installed and working, i have tested it with wordpress permanent links and it works fine.
Now i have another website where want to apply the url change.
my main domain : www.mydomain.com
the current adress for my posts. www.mydomain.com/post.php?id=111
i need to change this adress to:
www.mydoman.com/year/month/post title here
EDIT!
For example this works great for me
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^id=([^/.&]+)/?$
RewriteRule ^post\.php$ /%1? [NS,R=301,L]
RewriteRule ^([^/.]+)/?$ post.php?id=$1&redirect=no [NS,QSA]
but it only show www.mydomain.com/postID
Please any kind of help ?
You'll have to add the ID to your URL, there's just no other simple way to do it:
URL = www.mydoman.com/year/month/post-title/111
RewriteEngine On
RewriteRule ^.*/.*/.*/([0-9]*)$ post.php?id=$1 [L]
Related
I don't have an idea how can I remove %2523 from URL made by GET in php. I want to redirect users to page without that. Sometimes it has # on string beggining, and that's why it generates that "%2523".
For example, want to redirect them from something like:
localhost/catalog/value/%2523string
to
localhost/catalog/value/string
My current .htaccess file:
Options -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/catalog/value\.php\?value=([^/]*)\s [NC]
RewriteRule ^ /catalog/value/%1? [R=301,L]
RewriteRule ^catalog/([^/]*)$ /value/value.php?color=$1 [L]
Hopefully you can help me with that, trying from yesterday and still didn't nothing works.
Finally i solved that by adding this at the .htaccess beggining:
RewriteRule ^([^%]*)\%23(.*)$ /catalog/value/$2 [R=301,L]
I want to setup a redirect on my site to go to a different domain which I am able to do so with this rewrite rule:
RewriteEngine on
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]
This works great but there are also a few pages that I want to completely change the url as well as redirect to the new domain. Here is an example:
1.) Here is an example url to my old domain. https://www.olddomain.com/product-tag/[tag-name]/. I want this go to https://www.newdomain.com/parts?category=[tag-name]/.
2.) Here is an example url to my old domain. https://www.olddomain.com/product-categories/[category-name]/garbage. I want this go to https://www.newdomain.com/parts?category=[category-name]/.
I was hoping that adding something like this would do the trick but it does not seem to be working:
RewriteEngine on
RewriteRule ^/product-tag/(.*)$ https://www.newdomain.com/parts?category=$1 [R=301,L]
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]
How can I achieve this?
Have it like this:
RewriteEngine on
# handle both specific URL redirects
RewriteRule ^/?product-(?:tag|categories)/([\w-]+) https://www.newdomain.com/parts?category=$1 [R=301,L,NC,QSA]
# redirect everything else
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L,NE]
i know this is a common question but i cannot figure this one out.
I have the following URL:
http://buildsanctuary.com/viewbuild.php?id=3&title=this_is_a_title&page=1
What i wish is the URL to be:
http://buildsanctuary.com/viewbuild/3/this_is_a_title/1
Normally for mod rewrites i would send the user to the link i want and let htaccess do all the work.
So in this case i have tried linking the users to the preferred URL style and rewriting the URL but to no avail.
Any help on how i should be handling this? I want to send the users to the preffered URL but then can i use htaccess to allow me to process the page and URL $_GET information in the same way as the normal dynamic URL?
I have tried the mod rewrite generators etc but nothing works.
This is what the gens have given me:
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.php$ /viewbuild.php?id=$1&title=$2&page=$3 [L]
Thanks.
Fix the generator rule:
RewriteRule ^viewbuild/([^/]*)/([^/]*)/([^/]*)\.php$ /viewbuild.php?id=$1&title=$2&page=$3 [L,QSA]
However, I would do it this way:
RewriteRule ^([^/]*)/(.*) /$1.php/$2 [L]
and then map what you get in $_SERVER['PATH_INFO'] to you preference in PHP.
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/([^/]+)/([^/]+)/([^/]+)/?$ /$1.php?id=$2&title=$3&page=$4 [L,QSA]
Should do the trick
^viewbuild/([0-9]+)/([a-z_]+)/-([0-9]+)/?$ viewbuild.php?id=$1&title=$2&page=$3 [NC,L]
i changed my cms and have now some old urls, that are still linked by other websites.
Now i have to redirect the old links to my new sites Start Page.
The old CMS was installed in a subfolder named "contentms". The new CMS is installed in the root-folder.
Old Urls look like: mywebsite.com/contentms/content.php?idcat=62
When i try to forward it using my rewrite rule:
RewriteEngine on
RewriteRule ^contentms/.*$ http://www.mywebsite.com/ [R=301,L]
It works, but there will appear:
http://www.mywebsite.com/?idcat=62
But i want to have only http://www.mywebsite.com, without the "?idcat=62" added to the external url.
Maybe you have a solution for me.
Thanks!
Give this a try and see how it works for you.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/contentms
RewriteRule ^(.*) http://www.mywebsite.com/? [R=301,L]
You can do this in the same line.
RewriteEngine on
RewriteRule ^contentms/.*$ http://www.mywebsite.com/? [R=301,L]
i want to show only domain name in address bar. i am new in programming nd using core php.
my .htaccess code is:
<IfModule mod_rewrite.c>
RewriteBase /
Options +FollowSymlinks -MultiViews
RewriteEngine on
# to make `/path/index.php` to /path/
RewriteCond %{THE_REQUEST} ^GET\s(.*/)index\.php [NC]
RewriteRule . %1 [NE,R=301,L]
RewriteCond %{THE_REQUEST} ^GET\s.+\.php [NC]
RewriteRule ^(.+)\.php$ /$1 [NE,R=301,L,NC]
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule . %{REQUEST_URI}.php [L]
</IfModule>
this is working fine but it shows the result like this
http://mysite.com/about
http://mysite.com profile_view?name=Apoorva%20Chauhan%20GMAIL%20&&%20user_type=User
i just want to hide complete url expect my domain name. url should be like this www.mysite.com/ no matter which link i clicked.
and above code only hide index.php completely.
My project deadline is already over i wasted 1 week on this topic. but i failed.
Please help me.
Thanks In Advance.
i used javascript to hide or change the entire url. and it's working fine now. but i am not completely satisfy with it.
<script type='text/javascript'>
if(history.replaceState) history.replaceState({}, "", "/");
</script>
Note : where / is the path u want to show.
it shows the url like mysite.com no matter which link i have clicked. but i have a problem with this code while reloading the page the complete url with query string blinks into address bar.
Use document.location.replace('URL');
The browser will not build a history,
and will just show the base http://URL/#
no matter what page within the site.
I think (not sure from the description) what you want is a single page website. If that's the case, you're approaching this all wrong. This is not achieved through .htaccess, but through js/ajax. You can find here an example of such a web application.