I need some push with this, I have website that URL structure looks like this
domain.com/folder/index.php?name=asdasdAs2
How do I remove this part of the URL index.php?name= so it looks like this
domain.com/folder/asdasdAs2
The passed value (asdasdAs2) sometimes also contain these symbols ( . ) or ( - ) or ( _ ) so it will look like this (asd.asdAs2) or (asdasd_As2) or (asd-aSd-As2)
I've been trying with this code in my .htaccess file but it doesn't work.
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteRule ^/folder/(.*) /folder/index.php?name=$1
and this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>
and this one too
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)$ $1/index.php?name=$2 [L]
The last one does the job but only with alphanumeric word ex.(asdasdAs2) but not on (asd.asd) or (asd_asdas2)
With your shown samples please try following .htaccess rules file.
Please make sure to:
Keep your .htaccess file along with folder named folder.
Clear your browser cache before testing your URLs.
RewriteEngine ON
##External redirect rules here.
RewriteCond %{THE_REQUEST} \s/(folder)/index\.php\?name=(\S+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite rules from here...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ $1/index.php?name=$2 [QSA,L]
Related
I'm in the process of trying to prettify my URLs
From: http://localhost/blog.php?id=1
To: http://localhost/blog/1
I've added the below to my .htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^blog/([a-zA-Z0-9]+)$ blog.php?id=$1 [NC,L]
From my understanding that should now redirect when I call my "to" url in PHP header("location: /blog/".id); it takes me to the relevant page, and my $_GET['id'] should have a value. It's coming up empty
I've been messing around with a few different regular expressions, but I don't think that's the issue.
In the apache config I changed "AllowOverride" to 'All'
To check to see if the .htaccess was even being used I put in some invalid regex, and got an error in apache_error.log
I've been on a ton of different pages asking the same thing, and watched plenty of YouTube vids, but I can't see what I'm missing
Have your htaccess Rules file in following manner. Please make sure to clear your browser cache before testing your URLs.
Options +FollowSymLinks -MultiViews
RewriteEngine On
##Rules for external redirect to blog/1 here.
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} \s/(blog)\.php\?id=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Rules for internal rewrite to blog.php file here.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^blog/([\w-]+)/?$ blog.php?id=$1 [QSA,NC,L]
##Rules for internal rewrite to index.php file here.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ index.php?id=$1 [QSA,NC,L]
try this .
1.
Options +FollowSymLinks
RewriteEngine on
RewriteRule blog/id/(.*)/ blog.php?id=$1
RewriteRule blog/id/(.*) blog.php?id=$1
example url :- http://localhost/blog/id/1/
Directory Type URL
I'm here to ask for advice about the .htaccess file that I can't configure as I would like.
I have a site, let's say :
www.mysite.com/php/blog.php
I would like the visitor to see in the address bar only:
www.mysite.com/blog
This is what the .htaccess file contains:
Options +FollowSymlinks
Options All -Indexes
RewriteEngine On
RewriteRule ^$ index.php #This line is to hide index.php on the home page, maybe it's not the right way to do it
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^php/([0-9a-zA-Z]+).php$ $1 [L] #I tried to write this, but it doesn't work
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I suspect that this question has been asked many times, but I have really tried, without success.
Can you help me, please?
Thanks !
Your patter is wrongly expecting URI to start with /php/ which is not the case here. Also keep http -> https rules at top and then handle .php extension rule like this:
RewriteEngine On
# http -> https redirect
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# To externally redirect /php/file.php to /file
RewriteCond %{THE_REQUEST} \s/+(?:php/)?(\S+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# To internally forward file to /php/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/php/$1.php -f
RewriteRule ^(.+?)/?$ php/$1.php [L]
After some help from another question i managed to figure out about .htaccess on my website for Friendly SEO links.
My public_html folder contains those files
index.php
.htaccess
buisnessdetails.php
eventDetails.php
My htaccess so far is this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)\ (.*)$ /$1-$2 [L,R=301]
RewriteCond %{THE_REQUEST} /eventDetails\.php\?id=(.+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /eventDetails.php?id=$1&name=$2 [L]
</IfModule>
So when someone clicks an href which has http://sourtouki.gr/123/abc
the htaccess file goes to the
eventDetails.php file.
But now i want it to change like this
i've edited my public_html folder like this
index.php
events(folder)
2.1 eventDetails.php
buisness(folder)
3.1 buisnessdetails.php
So with these changes i want to do the following thing
Changed the href link to
http://sourtouki.gr/events/123/abc
What changes i must do to the .htaccess file so it can understand that if someone pushes the above link, to go to the eventDetails.php which is inside events folder??
And is it going to be editable so i can add also buisness folder inside that rewrite rule?
You can use something like :
RewriteEngine on
RewriteRule ^(.*)\ (.*)$ /$1-$2 [L,R=301]
RewriteCond %{THE_REQUEST} /events/eventDetails\.php\?id=(.+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /events/%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^events/([^/]+)/([^/]+)/?$ /events/eventDetails.php?id=$1&name=$2 [L]
I'm need some help with an htaccess rewrite. I would like to do a clean url setup that is dynamic.
For example
mydomain.com/pagename/var1/var2/
mydomain.com/pagename2/var1/var2/var3/etc
mydomain.com/pagename3/var1/var2/var3/etc
I would like the first level to be alway be the filename in the rewrite?
mydomain.com/pagename.php?v1=var1&v2=var2&v3=var3
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$0\.php -f [NC]
RewriteRule ^([^.]+)/?$ $0.php?v1=$1&v2=$2&v3=$v3 [L]
This will do your job done,
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^home/{0,1}$ pagename.php?v1=1[QSA,L]
RewriteRule ^sone/{0,1}$ pagename.php?v1=2[QSA,L]
RewriteRule ^music/{0,1}$ pagename.php?v1=3[QSA,L]
RewriteRule ^video/{0,1}$ pagename.php?v1=3[QSA,L]
</IfModule>
and the link look like that: mydomain.com/home but the real link is mydomain.com/pagename.php?v1=1
URL : http://domainname.com/index.php?p=top-games
I need to rewrite this as http://domainname.com/top-games
How I do this using htaccess file? Please can any one give me the htaccess code.
Thanks
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]
</IfModule
Create .htaccess file in your root folder and paste code
You're probably looking for redirect in reverse direction.
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ /index.php?q=$1 [L,QSA]