rewriting url using htaccess [closed] - .htaccess

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I'm pretty new to .htaccess and I'm trying to rewrite the following URL structure:
http://www.example.com/groups/menu.php?id=This is Group Name With Number 25
into:
http://www.example.com/groups/this-is-group-name-with-number-25/
as you can see I need to include - as a separator instead of empty spaces, and I also need to have all characters be lowercase, but allow numbers.
Now since "This is Group Name With Number 25" is user-generated, do I need to make any additional changes within my PHP script so it can generate that kind of URL in web browser or will the .htaccess file handle everything?

You can use external rewriting for such things. This one will be a simple few-line perl script. See apache documentation for "External Rewriting Program".
RewriteMap mapname prg:/path/to/program

You should be handling a path creation like that in PHP, before it even gets sent to the HTML and into an anchor for someone to click on. Not only does it contain spaces which will get converted into %20 and make the URL unreadable, it contains uppercase letters!
There is no efficient way to lowercase your letters and replace all the spaces with dashes efficiently. Most methods will use a bunch of extra HTTP requests.

Related

Replace URL in markdown files in python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have big markdown file. Is there any way to change /foo in my url by /bla. That is, I want to replace
[text](/foo/some-long-url/a.html)
for
[text](/bla/some-long-url/a.html)
(all ocurrences).
I know I could compile markdown file to html and use html parsers (like BeautifulSoup) to do that. But I want to do that, on the source file.
Prefered python or shell solutions.
I mean you can always replace "/foo" to "/bla" directly in the source using sed?
sed 's/\/foo/\/bla/' source.md >> destination.md
If it catches anything unwanted, you can just tweak the regular expression a bit to be more specific.

Batch files - names [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have a code that looks for png files with a specific pattern on the desktop and moves them to another directory.
While going over the files, I want to check if there is the pattern in the name.
This is how I did it:
for %%f in (C:\Users\user\Desktop\*.png) do (
if %%f==Hearthstone Screenshot*.png (
move %%f C:\destination\
)
)
Note: All the needed files start with Hearthstone Screenshot then some numbers.
My main problem is in line 2. I can't make it work.
Depending upon you needs, perhaps this is what you're looking for…
#RoboCopy "%UserProfile%\Desktop" "%UserProfile%\Desktop\HearthStone_Screenshots" "HearthStone Screenshot*.png" /MOV>Nul 2>&1
This should automatically create the holding directory, HearthStone_Screenshots if it doesn't already exist.
Note:I have corrected what I'm assuming to be your very poor spelling issues. If those files and directories should be named using ea instead of ee please re-adjust as necessary.
What's wrong with this:
move C:\Users\user\Desktop\HearthstoneScreanshot*.png C:\Users\user\Desktop\Hearthstonescreanshot\

Portable bourne shell script without using functions of modern shells as bash, ksh, zsh etc [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
First of all I want thank all of you who will help me solve this. I have an exam tomorrow and I have to prepare this script for the exam. I am really new to linux and those bourne shell script.
My project should be a portable bourne shell script which scans a directory for the following files: header.txt, footer.txt and content.txt. The content of the files should be read but ignoring the lines starting with # and this content should be used for generating an HTML page with the following header, footer and content. This files can contain any text and/or HTML code but the cannot contain head and body tags. When scanning the directory the script have to compare the date of the last change of the files (header.txt, footer.txt and content.txt) with the date of the last change of the HTML page (if you have one already) and if the date of the last edit on the files is newer than the one on the HTML page the script should generate a new HTML page with the latest content.
Guys thank you very much as this is very important for me. Please help me getting this done.
Thank you very much!
To remove lines beginning with # try this:
grep -v "^#" file
To remove lines that may contain spaces (or blank characters) before a #:
grep -v "^[[:blank:]]*#" file

.htaccess code, is this example good coding practice? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Now that my feet are officially wet with .htaccess I have a new question. In one of the many tutorials I have bookmarked, the author recommends placing this bit of code at the beginning of the .htaccess file:
AddDefaultCharset UTF-8
RewriteEngine On
RewriteBase /
I can understand the issues of avoiding parsing issues with that first line, so what I want to know is, aside from RewriteEngine On are the other two lines good practice or just adding bloat?
Many thanks!
The RewriteBase / line is sometimes used to resolve relative URIs in the target and/or patterns of RewriteRule's. For example, if an htaccess file is in the /foo directory, and you have rules that might look something like this:
RewriteEngine On
RewriteBase /foo/
RewriteRule ^bar$ index.php?bar [L]
Here, the rule's target index.php?bar is a relative URI and the base gets prepended to it, resulting in the URI: /foo/index.php?bar. When the rule's target is relative, apache will make a guess as to whether the URI is a file-path or a URL-path, and it doesn't always guess correctly. With the RewriteBase /foo/, apache knows that the /foo/index.php is a URL-path. There could be instances where the rewrite base doesn't match the folder that it's in, but the result is still the same. It acts as a URI base for the relative URI's that are in the rules.
Having it doesn't hurt, unless for some reason you want certain relative URI's to actually map to file-paths.
The AddDefaultCharset directive doesn't apply to the character set of the htaccess file, it's part of the response that the webserver gives to requests when the requested content is of type text/html or text/plain. Again, doesn't hurt to have this in your htaccess file unless you're text or html content is actually some other encoding (like *shift_jis* for example).

mod_rewrite issue or maybe my server is the issue? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm having a bit of a fit here. I'm wading into the vast pool of .htaccess in order to rewrite my URLs to be SEO friendly.
I have been researching this all day. I take code snippets from various tutorials and SO posts, yet I get no results and most of the time, no errors.
I have a cPanel dedicated server running Apache 2.0. I called my host, LunarPages, and verified that mod_rewrite was installed and it is, and apparently is working fine.
where I'd like to start is changing the name of index.php to /home/ as in http://www,website.com/home/ making the trailing slash optional as well as home being case insensitive.
Literally, everything I try is doing nothing, it's as though the request is being ignored completely.
I'm writing the .htaccess file in Notepad on my PC and uploading it with FileZilla with the transfer type set to ASCII.
where I'd like to start is changing the name of index.php to /home/ as in http://www,website.com/home/ making the trailing slash optional as well as home being case insensitive.
Try:
RewriteRule ^/?home/?$ /index.php [L,NC]
Note that if you have any relative links (like to scripts or CSS) in index.php and you go to http://www,website.com/home/, the relative links will have /home as a base (instead of /). And you'll either need to make those links absolute or add a URI base to the page header:
<base href="/">

Resources