I looking to parse only one specific url in htaccess in following format
https://example.com/apps/store/customdesign/shopid/2/designid/Design_10
into
https://example.com/apps/store/customdesign.php?shopid=2&designid=Design_10
I tried following things
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/customdesign$
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /customdesign.php?$1=$2&$3=$4
</IfModule>
I assume you are looking for a Mod_Rewrite solution, so first make sure you have the mod rewrite extension active, then write your URL Rewrites;
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
^apps/store/customdesign/shopid/([0-9]+)/designid/([0-9A-Z_]+)$ /apps/store/customdesign.php?shopid=$1&designid=$2 [QSA,NC,L]
</IfModule>
I have provided the solution I would most-likely use if this were my problem, however you should look into RegEx as well as your specific installation and hosting permissions before continuing with URL Rewrites. Spend some time and do some research!
Related
I am trying to implement SEO friendly URLs using .htaccess and PHP.
I have achieved 90% of my goal and struggling with just one use case.
Here is what happing, when I access the following url
http://somesite.com/cms/movies/tarzan
it lands on
my-handler.php?the_url=movies/tarzan
This is perfect and that is what I want because then I manage it myself. The real problem is when I don't provide any slugs, then it lists the directory (means show all files and folders in it)
http://somesite.com/cms/
Can someone please help me fix following .htaccess content, so that even if I don't provide slug it should still be handled by my-handler.php instead of lisiting full directory?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cms/
RewriteCond %{REQUEST_FILENAME} !/(admin|css|fonts|ico|include|js)/
RewriteRule ^my-handler\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /cms/my-handler.php?the_url=$1 [L,QSA]
</IfModule>
Solved
As per #Roman suggestion, I added the following to the above listing and it solved my problem. Plus I do not have to compromise on accessing physical directories RewriteCond %{REQUEST_FILENAME} !-d
DirectoryIndex my-handler.php
At first you have to set the DirectoryIndex to handle every request which points to / with your my-handler.php. This can be done by adding the line to your .htaccess
DirectoryIndex my-handler.php
To disable the directory listing, you have to forbid the listing by adding the following line to your .htaccess
Options -Indexes
Remember that this configuration is per .htaccess and just for the directory you are placing the file in. If you want to make changes for your whole webserver, you can edit the httpd.conf and search for
Options Indexes
and remove the Indexes option.
Documentation
The listing is provided by the mod_autoindex module.
Nice side-fact
If you just want to disable the listing of specific file-types like .env or .php files, you can add the option IndexIgnore *.php to you .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cms/
RewriteCond %{REQUEST_FILENAME} !/(admin|css|fonts|ico|include|js)/
RewriteRule ^my-handler\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css|json|woff|ttf)
RewriteRule ^(.*)$ /cms/my-handler.php?the_url=$1 [L,QSA]
</IfModule>
So I am in a bit of a soup here.
I need to make a friendly URL.
This is the URL where I enter the search values project_name and version
localhost:8080/demo_webpages_project/retrieval.html
This is where it takes me to on submitting the values
localhost:8080/demo_webpages_project/download.php?project_name=QT&version=3.1.2
I want the URL in the following form
localhost:8080/demo_webpages_project/download/QT/3.1.2
I tried doing this using .htaccess but not really finding a solution
The following is the code for the .htaccess file.
<IfModule mod_rewrite.c>
#Turn the engine on
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#attempt1
#RewriteRule ^(.*)/$ download.php?project_name=$1&version=$1
#RewriteRule ^/(.*)$ download.php?version=$1
#attempt2
#RewriteRule ^(.*)/(.*)$ download.php?project_name=$1&version=$2 [L,NC,QSA]
#RewriteRule ^(.*)$ download.php?version=$1
</IfModule>
I would be really grateful if someone could help me out with this. This is the first time I am working on something on this and am lost.
Thanks
Have this .htaccess inside /demo_webpages_project/:
Options -MultiViews
RewriteEngine on
RewriteBase /demo_webpages_project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ download.php?project_name=$1&version=$2 [L,QSA]
According to this article, you want a mod_rewrite (placed in an .htaccess file) rule that looks something like this:
RewriteEngine on
RewriteRule ^/news/([0-9]+)\.html /news.php?news_id=$1
And this maps requests from
/news.php?news_id=63
to
/news/63.html
Another possibility is doing it with forcetype, which forces anything down a particular path to use php to eval the content. So, in your .htaccess file, put the following:
<Files news>
ForceType application/x-httpd-php
</Files>
And then the index.php can take action based on the $_SERVER['PATH_INFO'] variable:
<?php
echo $_SERVER['PATH_INFO'];
// outputs '/63.html'
?>
I have developed a project without using any framework. I want to redirect a page to specific php file (example : movie/movie.php) when click on this
Click me
link. I have created .htaccess file and currently it look like this.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/movie/([0-9]+)/$ http://localhost/tthtml/movie/movie_review.php [L]
</IfModule>
I have enable mod_rewrite module in httpd.conf file. I am using wamp server in windows machine.
I dont no how to do this. I have referenced few sites and I created this above rule in my own. Kindly any one help me to do this and feel better if your answer have explonation as well. Thanks in advance.
Modify the rule as follows:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^movie/([0-9]+)/(.*)$ http://localhost/tthtml/movie/movie_review.php [L]
</IfModule>
The rule that you placed was not working because it was comparing only the string "/movie/1/", while you actually want to match "/movie/1/Baashha-Suresh-Krishna-1995".
For this to work, I have modified the RewriteRule directive as ^/movie/([0-9]+)/(.*)$ to accommodate the remaining string "Baashha-Suresh-Krishna-1995" or any other value that the application may have.
Trying to get www.example.com/test.php?archives=testing to www.example.com/archives/testing
According to godaddy they have mod_rewrite enabled by default
Here is my .htaccess file:
rewriteengine on
rewritecond %{HTTP_HOST} ^example.com$
rewriterule ^example\/(.*)$ "http\:\/\/www\.example\.com\/$1" [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^archives/(\w+)$ test.php?archives=$1 [L]
However this is not working, when i go to www.example.com/archives/test I get a 404, suggestions
I just left this in a comment but i might as well put it here so its seen easier. I wrote an answer for someone thats helped others out over time, and in the end this isn't exactly an answer to what your asking however its more of a stepping stone in the direction. The original question was asked how to work with short url strings and make them work in a fashion like your looking for, but rather copy and paste that answer here. Ill let you go there and read over it.
Its not to go without saying you will need to alter the rule a little for your specific needs but it will in the end serve its purpose for getting you where you want to be.
PHP dynamic DB page rewrite URL
You need some rewrite conditions to specify when this rule will be used. Without them, you will keep running the same rewrite rule indefinitely, giving you an error. Try:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^archives/(\w+)$ test.php?archives=$1 [L]
How about this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^archives/(.+)$ /test.php?archives=$1 [L]
</IfModule>
Without is being super clear what you are trying to get from your rewrites I suggest:
Options -MultiViews
ErrorDocument 404 default
RewriteBase /
I want to show the URL
http://www.example.com/blog/feedback
as
http://www.example.com/feedback
How can I do so using .htaccess?
You will need mod_rewrite to do this.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/feedback$ /blog/feedback
</IfModule>
Have a look here for a tutorial information on mod_rewrite.
EDIT:
If you are trying to move JUST /blog/feedback to /feedback then you will have to first move your base from /app/webroot/blog/ to /app/webroot/, edit all your rules to account for it and then add your new rule. Could be done like so:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /app/webroot/
RewriteRule ^/blog/index\.php$ - [L]
RewriteRule ^/blog/feedback$ /feedback [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /blog /app/webroot/blog/index.php [L]
</IfModule>
NB: This should work, but I'm not at my work station right now so I can't check it :( If anything goes wrong it's probably a typo somewhere - let me know.